/*
 * @title: admin工程调用后端api
 * @author: andy.ten@tom.com & xukaixing@hotmail.com
 * @Date: 2022-04-16 18:21:44
 * @LastEditors: andy.ten@tom.com
 * @LastEditTime: 2022-06-05 17:17:09
 * @version: 1.0.6
 * @copyright: copyright (c) 2022 andyten
 *  node: you can not copy and/or use and/or modify this program free,
 *  please reserve the segment above.Please mail me if you have any question.
 */
import fetch from '@/utils/ht.fetch';
import server from '@/api/ht.server';
const baseUrl = 'http://localhost:4701/';
// dict表选字典api
export const findDictFromTable = (dicType, q) => {
  if (process.env.NODE_ENV !== 'production') fetch.defaults.baseURL = baseUrl;
  return fetch.get(`${server.gateway_admin}/dictapi/findDictFromTable`, {
    params: {
      modelName: 'admin',
      vparam: dicType,
      query: q === undefined ? '' : q
    }
  });
};

// 用户查询请求api
export const findUsers = (data) => {
  if (process.env.NODE_ENV !== 'production') fetch.defaults.baseURL = baseUrl;
  return fetch.post(`${server.gateway_admin}/sysuser/findUsers`, data);
};

// 新增用户api
export const saveUser = (data) => {
  if (process.env.NODE_ENV !== 'production') fetch.defaults.baseURL = baseUrl;
  return fetch.post(`${server.gateway_admin}/sysuser/saveUser`, data);
};

// 更新用户api
export const updateUser = (id, data) => {
  if (process.env.NODE_ENV !== 'production') fetch.defaults.baseURL = baseUrl;
  return fetch.put(`${server.gateway_admin}/sysuser/updateUser/${id}`, data);
};

// import 导入url
export const importUser = () => {
  return `${baseUrl}excelapi/importExl`;
};

// import 获取导入成功数据
export const findImportUsers = (data) => {
  if (process.env.NODE_ENV !== 'production') fetch.defaults.baseURL = baseUrl;
  return fetch.post(`${server.gateway_admin}/sysuser/findImportUsers`, data);
};

// export 下载excel
export const exportUser = (data) => {
  if (process.env.NODE_ENV !== 'production') fetch.defaults.baseURL = baseUrl;
  return fetch.post(`${server.gateway_admin}/sysuser/exportUserData`, data, {
    responseType: 'blob'
  });
};

// 获取用户登录信息
export const findUserLoginInfo = (data) => {
  if (process.env.NODE_ENV !== 'production') fetch.defaults.baseURL = baseUrl;
  return fetch.post(`${server.gateway_admin}/sysuser/findUserLoginInfo`, data);
};

// export 请求查询导出列
export const findExportFields = (param) => {
  if (process.env.NODE_ENV !== 'production') fetch.defaults.baseURL = baseUrl;
  return fetch.get(`${server.gateway_admin}/excelapi/findTabExport`, {
    params: {
      btnId: param
    }
  });
};

// export 保存导出列
export const saveExportFields = (btnId, header, expId) => {
  if (process.env.NODE_ENV !== 'production') fetch.defaults.baseURL = baseUrl;
  return fetch.get(`${server.gateway_admin}/excelapi/saveTabExport`, {
    params: {
      btnId,
      header,
      expId
    }
  });
};
